package org.gwt.client.vista.dialogos;

import org.gwt.client.controlador.BotonListener;

import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.layout.FormData;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;

public class DialogoVector3D extends Dialog{

	private Button botonOk;
	private TextField<String> textFieldNombre;
	private NumberField numberFieldX, numberFieldY, numberFieldZ;
	private BotonListener botonListenerOkVector;
	private FieldSet fieldSetDatos;
//	private final SimpleComboBox<String> simpleComboTipoVector;

	public DialogoVector3D() {
		botonOk = new Button("Ok");
		setShadow(false);
		setHeading("Vector");
		setWidth("300");
		setButtons(Dialog.CANCEL);
		setHideOnButtonClick(true);
		addButton(botonOk);

		FormPanel formPanelVector = new FormPanel();
		formPanelVector.setPadding(5);
		formPanelVector.setBodyBorder(false);
		formPanelVector.setHeaderVisible(false);
		add(formPanelVector);

//		String vector = new String("Vector");
//		String vectorNormal = new String("VectorNormal");
//		simpleComboTipoVector = new SimpleComboBox<String>();
//		simpleComboTipoVector.setFieldLabel("Tipo de Vector");
//		simpleComboTipoVector.setTriggerAction(TriggerAction.ALL);
//		simpleComboTipoVector.add(vector);
//		simpleComboTipoVector.add(vectorNormal);
//		simpleComboTipoVector.setEditable(false);
//		simpleComboTipoVector.setSimpleValue(vector);
//		formPanelVector.add(simpleComboTipoVector, new FormData("100%"));


		textFieldNombre = new TextField<String>();
		textFieldNombre.setName("X:");
		textFieldNombre.setFieldLabel("Nombre");
		formPanelVector.add(textFieldNombre, new FormData("100%"));

		fieldSetDatos = new FieldSet();
		fieldSetDatos.setHeading("Definición");
		fieldSetDatos.setExpanded(false);
	    fieldSetDatos.setCheckboxToggle(true);

	    FormLayout formLayoutDatos = new FormLayout();
	    formLayoutDatos.setLabelWidth(75);
	    fieldSetDatos.setLayout(formLayoutDatos);

	    numberFieldX = new NumberField();
	    numberFieldX.setFieldLabel("X");
	    fieldSetDatos.add(numberFieldX, new FormData("100%"));

	    numberFieldY = new NumberField();
	    numberFieldY.setFieldLabel("Y");
	    fieldSetDatos.add(numberFieldY, new FormData("100%"));

	    numberFieldZ = new NumberField();
	    numberFieldZ.setFieldLabel("Z");
	    fieldSetDatos.add(numberFieldZ, new FormData("100%"));

	    formPanelVector.add(fieldSetDatos);
	    inicializarBotonOkVector();
	}

	public FieldSet getFieldSetDatos(){
		return fieldSetDatos;
	}

	public TextField<String> getTextFieldNombre(){
		return textFieldNombre;
	}

	public NumberField getNumberFieldX(){
		return numberFieldX;
	}

	public NumberField getNumberFieldY(){
		return numberFieldY;
	}

	public NumberField getNumberFieldZ(){
		return numberFieldZ;
	}

//	public SimpleComboBox<String> getSimpleComboTipoVector(){
//		return simpleComboTipoVector;
//	}


	private void inicializarBotonOkVector() {
		botonOk.addSelectionListener(new SelectionListener<ButtonEvent>() {
			public void componentSelected(ButtonEvent ce) {
				botonListenerOkVector.botonVector3DEvent();
			}
		});
	}

	public void addBotonListener(BotonListener listener){
		botonListenerOkVector = listener;
	}

	public void removeBotonListener(BotonListener listener){
		botonListenerOkVector = null;
	}

	public void hide(boolean clear){
		if (clear) clear();
		hide();
	}

	public void clear(){
		textFieldNombre.clear();
		numberFieldX.clear();
		numberFieldY.clear();
		numberFieldZ.clear();
	}
}
